package com.eigaland.change_machine.customview

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.util.AttributeSet
import android.view.Gravity
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.target.Target
import com.eigland.eigaland_lib.model.Label
import movie6.posprintercept2.extensions.dip
import movie6.posprintercept2.extensions.sp

public class LabelView(context: Context?,label: Label, attrs: AttributeSet?) : AppCompatTextView(context, attrs) {


    init {
        layoutParams = ViewGroup.LayoutParams(dip(label.w!!), dip(label.h!!))
        x = dip(label.x).toFloat()
        y = dip(label.y).toFloat()
        text = label.text
        textSize = sp(label.fontSize!!).toFloat()
        gravity = Gravity.CENTER


        try {
            label.bgColor?.let {
                var color = Color.parseColor(it)
                setBackgroundColor(color)

            }
            label.color?.let {
                setTextColor(Color.parseColor(it))
            }

        } catch (e: Exception) {
            setTextColor(Color.BLACK)
        }
    }
}